/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.dnd;

import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.HTMLTransfer;
import org.eclipse.swt.dnd.ImageTransfer;
import org.eclipse.swt.dnd.RTFTransfer;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.swt.dnd.URLTransfer;

import de.mnit.basis.daten.struktur.schluessel.S_SchluesselListe;
import de.mnit.basis.daten.struktur.schluessel.SchluesselListe;
import de.mnit.basis.fehler.Fehler;
import de.mnit.basis.swt.dnd.transfer.IDObjekt;
import de.mnit.basis.swt.dnd.transfer.IDTransfer;
import de.mnit.basis.swt.dnd.transfer.TextFormatObjekt;
import de.mnit.basis.swt.dnd.transfer.TextFormatTransfer;
import de.mnit.basis.sys.Ausgabe;


/**
 * @author Michael Nitsche
 * 14.01.2007	Erstellt
 * 12.06.2010	Überarbeitet
 * 08.11.2010	TextFormat-Transfer
 */
public enum DNDTYP implements S_DND {

	DATEI(	String[].class,		FileTransfer.getInstance()),
	TEXT(	String.class,		TextTransfer.getInstance()),
	HTML(	String.class,		HTMLTransfer.getInstance()),
	RTF(	String.class,		RTFTransfer.getInstance()),
	URL(	String.class,		URLTransfer.getInstance()),
	IMAGE(	String.class,		ImageTransfer.getInstance()),
	MN_ID(	IDObjekt[].class,	IDTransfer.getInstance()),
	MN_TEXTFORMAT(	TextFormatObjekt.class,	TextFormatTransfer.getInstance());


	public final Class<?> klasse;
	public final Transfer transfer;


	private DNDTYP(Class<?> klasse, Transfer transfer) {
		this.klasse=klasse;
		this.transfer=transfer;
	}


	public static Transfer[] gTransfers(DNDTYP[] typen) {
		int len=typen.length;
		Transfer[] erg=new Transfer[len];
		for(int i=0; i<len; i++)
			erg[i]=typen[i].transfer;
		return erg;
	}

	public static DNDTYP gTyp(TransferData dataType) {
		for(DNDTYP typ : DNDTYP.values())
			if(typ.transfer.isSupportedType(dataType))
				return typ;
		throw Fehler.sonstige.da_Untypisch(dataType);
	}

	// Typen können mehrmals enthalten sein!!!
	public static S_SchluesselListe<DNDTYP, TransferData> gTypen(TransferData[] dataTypes) {
		S_SchluesselListe<DNDTYP, TransferData> erg=SchluesselListe.neu();
		for(TransferData td : dataTypes) {
			DNDTYP typ=gTyp(td);
			Ausgabe.debug(dataTypes, typ);
			if(!erg.gSchluessel().kennt(typ))
				erg.plus(typ, td);
		}
		return erg;
	}

}
